package com.demo.controller;

import com.demo.service.StudentService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * 使用构造方法来实现Bean注入（官方推荐）
 */

// 千万不要忘记加注解
@Controller
public class StudentController2 {

    // 2. 使用构造方法注入的方式来获取Bean
    private StudentService2 studentService;

    @Autowired
    //@Resource
    public StudentController2(StudentService2 studentService) {
        //this.studentService = new StudentService(); // 这是传统的写法

        this.studentService = studentService;
    }

    public void sayYe() {
        studentService.sayYe();
    }

}
